#include "mainwindow.h"
#include "filechoosewidget.h"
#include <DTitlebar>
#include <DMainWindow>
#include <QDragEnterEvent>
#include <QDebug>
#include <unistd.h>
#include <stdlib.h>
#include <string>
bool sound;

DWIDGET_USE_NAMESPACE
MainWindow::MainWindow(QWidget *parent)
    : DMainWindow(parent),
        m_menu(new QMenu),
        m_killxwinwrap(new QAction("关闭动态壁纸")),
        m_nosoundrun(new QAction("无声运行")),
        m_soundrun(new QAction("正常运行"))

{
    DTitlebar *tb = titlebar();
    //按钮互斥
    howGroup = new QActionGroup(this);
    howGroup->addAction(m_nosoundrun);
    howGroup->addAction(m_soundrun);

    m_menu->addMenu(menu_how);
    m_soundrun->setCheckable(true);
    m_nosoundrun->setCheckable(true);
    menu_how->setTitle(tr("运行方式"));
    menu_how->addAction(m_nosoundrun);
    menu_how->addAction(m_soundrun);
    m_menu->addAction(m_killxwinwrap);
    titlebar()->setMenu(m_menu);
    w = new FileChooseWidget;

    connect(m_nosoundrun,&QAction::triggered,[=](){sound=false;system("touch ~/.config/OneWallpaper/nosound");});
    connect(m_soundrun,&QAction::triggered,[=](){sound=true;system("rm ~/.config/OneWallpaper/nosound");});
    connect(m_killxwinwrap,&QAction::triggered,[=](){FileChooseWidget::killxwinwrap();});

            /*//窗体毛玻璃 实验性
            setAttribute(Qt::WA_TranslucentBackground, true);
            tb->setAttribute(Qt::WA_TranslucentBackground, true);
            setTranslucentBackground(true);
            setEnableBlurWindow(true);
            */

    //connect(m_killxwinwrap, &QAction::triggered, this, &FileChooseWidget::killxwinwrap);
    resize(w->size()); //设置窗口大小
    //setWindowOpacity(0.5);
    setFixedSize(480, 340);
    //setTitlebarShadowEnabled(false);//取消标题栏阴影
    setCentralWidget(w);
    tb->setTitle("");
    tb->setIcon(QIcon::fromTheme(":/new/prefix1/images/icon.svg"));
    //tb->setBlurBackground(true);//启用标题栏毛玻璃
    std::string dir=getenv("HOME");
    dir.append("/.config/OneWallpaper/nosound");
    if(access (dir.data(),0) == 0)
    {
        qDebug()<<"无声运行";
        sound=false;
    }
    else
    {
        qDebug()<<"正常运行";
        sound=true;
    }
    if(sound==true)
        m_soundrun->setChecked(true);
    else
        m_nosoundrun->setChecked(true);

}

MainWindow::~MainWindow()
{

}
